package p1001;

import java.util.HashMap;
import java.util.Map;

/**
 * DogAndChickCalc
 * 
 * @author 오스템임플란트 jw
 * @since 2013. 12. 13.
 * @version 1.0
 * @see
 * 
 * <pre>
 * << 개정이력(Modification Information) >>
 *   
 *	  수정일  		수정자				수정내용		
 *	----------		------		------------------------
 *	2013. 12. 13.    jw				최초 생성
 *
 * </pre>
 */
public class DogAndChickCalc {
	
	private int totCnt;
	private int totLegs;
	
	public Map<String, Integer> calcDogAndChick(int totCnt, int totLegs) {
		this.totCnt = totCnt;
		this.totLegs = totLegs;
		
		Map<String, Integer> resultMap = new HashMap<String, Integer>();
		
		int dogCnt = 0;
		int chickCnt = 0;
		
		//index : 강아지수 totCnt - index : 병아리 
		for(int index = 0; index < totCnt; index++ ){
			if(this.checkCnt(index, totCnt-index)){
				dogCnt = index;
				chickCnt = (totCnt-index);
				break;
			}
		}
		
		resultMap.put("dog", dogCnt);
		resultMap.put("chick", chickCnt);
		
		return resultMap;
	}
	
	private boolean checkCnt(int dogCnt, int chickCnt){
		if(dogCnt*4 + (totCnt-dogCnt)*2 == totLegs)
			return true;
		else
			return false;
	}
}

